android httpurlconnection [closed]

Posted by user620451 on Stack Overflow See other posts from Stack Overflow or by user620451
Published on 2011-02-16T22:18:28Z Indexed on 2011/02/16 23:25 UTC
Read the original article Hit count: 214

Filed under:
|

hi im new android developer i am trying to login to my asterisk server passing my username and password it works good but when i am trying to request anther url to the server after login i get access denied and i now the problem because the login connection has disconnected so i want a way to request to urls the first one is login to the server and the second is to do something else after login

please help and thx anyway

this is a part of my code i want to request this 2 url

url1="http://192.168.1.7:8088/rawman?action=login&username=admin&secret=admin"
url2="http://192.168.1.5:8088/rawman?action=updateconfig&reload=yes&srcfilename=users.conf&dstfilename=users.conf&Action-000000=newcat&Cat-000000=6001&Var-000000=&Value-000000="

public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    tv1 = (TextView) this.findViewById(R.id.display);
    ed1 = (EditText) this.findViewById(R.id.editText);
    bt1 = (Button) this.findViewById(R.id.submit);
    bt1.setOnClickListener(new OnClickListener() {
        public void onClick(View view) {
        {
            try{
                ServerRequest(url1);
                ServerRequest(url2);
            } catch(Exception e) {
                Log.v("Exception",
                    "Exception:"+e.getMessage());
            }
        }
        }
    });
}
public String ServerRequest(String serverString)
            throws MalformedURLException, IOException {
    String newFeed=serverString;
    StringBuilder response = new StringBuilder();
    Log.v("server","server url:"+newFeed);
    URL url = new URL(newFeed);
    HttpURLConnection httpconn
            = (HttpURLConnection) url.openConnection();
    if(httpconn.getResponseCode()==HttpURLConnection.HTTP_OK) {
        BufferedReader input = new BufferedReader(
                new InputStreamReader(httpconn.getInputStream()),
                8192);
        String strLine = null;
        while ((strLine = input.readLine()) != null) {
            response.append(strLine);
        }
        input.close();
    }
    tv1.settext(response);
    return response.toString();
}

© Stack Overflow or respective owner

Related posts about android

Related posts about http